--- interact_link: content/08/10/plotly8-10.ipynb kernel_name: python3 kernel_path: content/08/10 has_widgets: false title: |- Sub Plots pagenum: 23 prev_page: url: /08/09/plotly8-9.html next_page: url: /08/11/plotly8-11.html suffix: .ipynb search: subplots id want plotlysubplots plot ly python good display multiple view together either show trends relationship create pseudo dashboard plotlysubplotsbasic basic subplot plotlysubplotscustom customizing comment: "***PROGRAMMATICALLY GENERATED, DO NOT EDIT. SEE ORIGINAL FILES IN /content***" ---
Sub Plots

Subplots

Subplots are good to use:

  • When you want to display multiple view together to either show trends or relationship.
  • When you want to create a pseudo "dashboard."

Basic Subplot

from plotly.subplots import make_subplots
import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, plot
from IPython.core.display import display, HTML
init_notebook_mode(connected=True)

fig = make_subplots(rows=1, cols=2)

fig.add_trace(
    go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
    row=1, col=2
)

fig.update_layout(height=600, width=800, title_text="Subplots")

plot(fig, filename = 'figure8-10-1.html')
display(HTML('figure8-10-1.html'))

Customizing Subplots

fig = make_subplots(rows=1, cols=2)

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3],
        y=[4, 5, 6],
        mode="markers+text",
        text=["Text A", "Text B", "Text C"],
        textposition="bottom center"
    ),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(
        x=[20, 30, 40],
        y=[50, 60, 70],
        mode="markers+text",
        text=["Text D", "Text E", "Text F"],
        textposition="bottom center"
    ),
    row=1, col=2
)

fig.update_layout(height=600, width=800, title_text="Annotations and subplots")

plot(fig, filename = 'figure8-10-2.html')
display(HTML('figure8-10-2.html'))